package com.sc.service.impl.csm;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.domain.HouseFacility;
import com.sc.dto.HouseFacilityDTO;
import com.sc.mapper.csm.HouseFacilityMapper;
import com.sc.service.csm.IHouseFacilityService;
import org.springframework.stereotype.Service;

@Service
public class HouseFacilityServiceImpl extends ServiceImpl<HouseFacilityMapper, HouseFacility> implements IHouseFacilityService {

    @Override
    public Page<HouseFacility> pageQuery(HouseFacilityDTO houseFacilityDTO) {
        QueryWrapper<HouseFacility> wrapper = Wrappers.emptyWrapper();
        String facilityName = houseFacilityDTO.getFacilityName();

        if (facilityName != null && !facilityName.isEmpty()) {
            wrapper = new QueryWrapper<>();
            wrapper.like("facility_name", facilityName);
        }

        Page<HouseFacility> page = new Page<>(houseFacilityDTO.getPageNum(), houseFacilityDTO.getPageSize());
        Page<HouseFacility> houseFacilityPage = page(page, wrapper);
        return houseFacilityPage;
    }
}
